const express = require('express');
const router = express.Router();
const R = require("../util/json")
const connection = require("../util/db")
const json = require("../util/jsonFormat")

router.get("/select",function (req, res) {
    let sql = "select * from role where 1 = 1 ";
    const objs=[];
    if(req.query.roleName){
        sql+="and role_name like ?";
        objs.push(`%${req.query.roleName}%`)
    }
    sql+=" order by id desc ";
    connection.query(sql,objs,function (e,r) {
        if(e){
            throw e;
        }
        res.json(R.data(json.formatArray(r)));
    })
})

module.exports = router;
